﻿using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Drawing;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.ViewInfo;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Localization;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraPrinting;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using YanZhiwei.DotNet.DevExpress12._1.Utilities.Models;
using YanZhiwei.DotNet.DevExpress12._1.Utilities.Tool;
using YanZhiwei.DotNet2.Utilities.WinForm;
namespace YanZhiwei.DotNet.DevExpress12._1.Utilities
{
    /// <summary>
    /// GridControl帮助类
    /// </summary>
    public static class GridHelper
    {
        /*
         *参考：
         *一、如何解决单击记录整行选中的问题==>View->OptionsBehavior->EditorShowMode 设置为：Click
         *二、如何新增一条记录==>(1)、gridView.AddNewRow()(2)、实现gridView_InitNewRow事件
         *三、如何解决GridControl记录能获取而没有显示出来的问题==>gridView.populateColumns();
         *四、如何让行只能选择而不能编辑（或编辑某一单元格）==>(1)、View->OptionsBehavior->EditorShowMode 设置为：Click (2)、View->OptionsBehavior->Editable 设置为：false
         *五、如何禁用GridControl中单击列弹出右键菜单==>设置Run Design->OptionsMenu->EnableColumnMenu 设置为：false
         *六、如何隐藏GridControl的GroupPanel表头==>设置Run Design->OptionsView->ShowGroupPanel 设置为：false
         */
        #region  GridControl 数据绑定
        /// <summary>
        /// GridControl 数据绑定
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="gridControl">GridControl</param>
        /// <param name="t">实体类</param>
        public static void SetBindingSource<T>(this GridControl gridControl, T t) where T : class
        {
            BindingSource _bindingSource = new BindingSource();
            _bindingSource.Add(t);
            gridControl.DataSource = _bindingSource;
        }
        /// <summary>
        /// GridControl 数据绑定
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="gridControl">GridControl</param>
        /// <param name="source">IList</param>
        public static void SetBindingSource<T>(this GridControl gridControl, IList<T> source) where T : class
        {
            BindingList<T> _bindinglist = new BindingList<T>(source);
            BindingSource _bindingSource = new BindingSource(_bindinglist, null);
            gridControl.DataSource = _bindingSource;
        }
        /// <summary>
        /// GridControl 数据绑定
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="gridControl">GridControl</param>
        /// <param name="bindinglist">BindingList</param>
        public static void SetBindingSource<T>(this GridControl gridControl, BindingList<T> bindinglist) where T : class
        {
            BindingSource _bindingSource = new BindingSource(bindinglist, null);
            gridControl.DataSource = _bindingSource;
        }
        #endregion
        #region 单个实体类数据源绑定
        /// <summary>
        /// 单个实体类数据源绑定
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="gridcontrol">GridControl</param>
        /// <param name="t">实体类</param>
        public static void SetDataSource<T>(this GridControl gridcontrol, T t) where T : class
        {
            IList<T> _source = null;
            if (t != null)
                _source = new List<T>() { t };
            gridcontrol.DataSource = _source;
        }
        #endregion
        #region 设置水平滚动条，并且自动根据内容调整列宽
        /// <summary>
        /// 设置水平滚动条，并且自动根据内容调整列宽
        /// </summary>
        /// <param name="gridView">GridView</param>
        public static void HorzScroll(this GridView gridView)
        {
            gridView.BestFitColumns();
            gridView.OptionsView.ColumnAutoWidth = false;
            gridView.ScrollStyle = ScrollStyleFlags.LiveHorzScroll | ScrollStyleFlags.LiveVertScroll;
            gridView.HorzScrollVisibility = ScrollVisibility.Always;
        }
        #endregion
        #region 设置当没有数据行的提示信息『CustomDrawEmptyForeground』
        /// <summary>
        /// 设置当没有数据行的提示信息『CustomDrawEmptyForeground』
        /// </summary>
        /// <param name="gridView">GridView</param>
        /// <param name="e">CustomDrawEventArgs</param>
        /// <param name="noRecordMsg">提示信息</param>
        public static void DrawNoRowCountMessage(this GridView gridView, CustomDrawEventArgs e, string noRecordMsg)
        {
            if (gridView.RowCount == 0)
            {
                if (!string.IsNullOrEmpty(noRecordMsg))
                {
                    Font _font = new Font("宋体", 10, FontStyle.Bold);
                    Rectangle _r = new Rectangle(e.Bounds.Left + 5, e.Bounds.Top + 5, e.Bounds.Width - 5, e.Bounds.Height - 5);
                    e.Graphics.DrawString(noRecordMsg, _font, Brushes.Black, _r);
                }
            }
        }
        #endregion
        #region 显示行序号CustomDrawRowIndicator事件中使用
        /// <summary>
        /// 显示行序号CustomDrawRowIndicator事件中使用
        ///  gridView1.IndicatorWidth = 40;
        /// </summary>
        /// <param name="gridView">GridView</param>
        /// <param name="e">RowIndicatorCustomDrawEventArgs</param>
        public static void DrawSequenceNumber(this GridView gridView, RowIndicatorCustomDrawEventArgs e)
        {
            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
            {
                e.Info.DisplayText = (e.RowHandle + 1).ToString();
            }
        }
        #endregion
        #region 将列设置为button显示
        /// <summary>
        /// 将列设置为button显示
        /// 点击事件:ButtonClick( GirdView.OptionsBehavior.Editable = true;才能生效)
        /// </summary>
        /// <param name="col">GridColumn</param>
        /// <param name="caption">button名称</param>
        public static void ToButton(this GridColumn col, string caption)
        {
            RepositoryItem _colTtem = col.ColumnEdit;
            if (_colTtem != null)
            {
                RepositoryItemButtonEdit _buttonEdit = (RepositoryItemButtonEdit)_colTtem;
                _buttonEdit.Buttons[0].Kind = ButtonPredefines.Glyph;
                _buttonEdit.Buttons[0].Caption = caption;
                _buttonEdit.TextEditStyle = TextEditStyles.HideTextEditor;
            }
        }
        #endregion
        #region 获取选中行中列的值
        /// <summary>
        /// 获取选中行中列的值
        /// </summary>
        /// <param name="gridView">GridView</param>
        /// <param name="columnName">列名称</param>
        /// <returns>列的值</returns>
        public static object FocusedCellValue(this GridView gridView, string columnName)
        {
            return gridView.GetRowCellValue(gridView.FocusedRowHandle, columnName);
        }
        #endregion
        #region 打印gridControl
        static Func<PrintItem> printSettTmp;
        /// <summary>
        /// 打印gridControl
        /// </summary>
        /// <param name="gridControl">GridControl</param>
        /// <param name="printSetting">打印规则</param>
        /// <param name="showPreview">是否打印预览</param>
        public static void CustomePrint(this GridControl gridControl, Func<PrintItem> printSetting, bool showPreview)
        {
            using (PrintableComponentLink _print = new PrintableComponentLink(new PrintingSystem()))
            {
                PrintItem _printSetting = printSetting();
                _print.Component = gridControl;
                _print.Landscape = true;
                _print.PaperKind = _printSetting.PaperKind;
                printSettTmp = printSetting;
                if (_printSetting.PrintHeader)
                    _print.CreateMarginalHeaderArea += CreateMarginalHeaderArea;
                if (_printSetting.PrintFooter)
                    _print.CreateMarginalFooterArea += CreateMarginalFooterArea;
                _print.CreateDocument();
                if (showPreview)
                    _print.ShowPreview();
                else
                    _print.PrintDlg();
            }
        }
        static void CreateMarginalFooterArea(object sender, CreateAreaEventArgs e)
        {
            PrintItem _printSetting = printSettTmp();
            PageInfoBrick _rick = e.Graph.DrawPageInfo(PageInfo.None, _printSetting.FooterText, _printSetting.FooterColor,
              new RectangleF(0, 0, 200, 20), DevExpress.XtraPrinting.BorderSide.None);
            _rick.LineAlignment = BrickAlignment.Center;
            _rick.Alignment = BrickAlignment.Center;
            _rick.AutoWidth = true;
            _rick.Font = _printSetting.FooterFont;
        }
        static private void CreateMarginalHeaderArea(object sender, CreateAreaEventArgs e)
        {
            PrintItem _printSetting = printSettTmp();
            PageInfoBrick _rick = e.Graph.DrawPageInfo(PageInfo.None, _printSetting.HeaderText, _printSetting.HeaderColor,
              new RectangleF(0, 0, 200, 20), DevExpress.XtraPrinting.BorderSide.None);
            _rick.LineAlignment = BrickAlignment.Center;
            _rick.Alignment = BrickAlignment.Center;
            _rick.AutoWidth = true;
            _rick.Font = _printSetting.FooterFont;
        }
        #endregion
        #region 遍历GridView
        /// <summary>
        /// 遍历GridView
        /// </summary>
        /// <param name="girdview">GridView</param>
        /// <param name="loopRowRule">带每行值返回的委托</param>
        public static void LoopRows(this GridView girdview, Action<object> loopRowRule)
        {
            for (int i = 0; i < girdview.RowCount; i++)
            {
                object _rowValue = girdview.GetRow(i);
                loopRowRule(_rowValue);
            }
        }
        #endregion
        #region 自定义GridControl按钮文字
        /// <summary>
        ///  自定义GridControl按钮文字
        /// </summary>
        /// <param name="girdview">GridView</param>
        /// <param name="cusLocalizedKeyValue">需要转移的GridStringId，其对应的文字描述</param>
        public static void CustomButtonText(this GridView girdview, Dictionary<GridStringId, string> cusLocalizedKeyValue)
        {
            //eg:
            //private Dictionary<GridStringId, string> SetGridLocalizer()
            //{
            //    Dictionary<GridStringId, string> _gridLocalizer = new Dictionary<GridStringId, string>();
            //    _gridLocalizer.Add(GridStringId.FindControlFindButton, "查找");
            //    _gridLocalizer.Add(GridStringId.FindControlClearButton, "清空");
            //    return _gridLocalizer;
            //}
            //-------------------------------------------------------
            //Dictionary<GridStringId, string> _gridLocalizer = SetGridLocalizer();
            //gridView1.CustomButtonText(_gridLocalizer);
            BuilderGridLocalizer _bGridLocalizer = new BuilderGridLocalizer(cusLocalizedKeyValue);
            GridLocalizer.Active = _bGridLocalizer;
        }
        #endregion
        #region 格式化列
        /// <summary>
        /// 格式化列
        /// </summary>
        /// <param name="girdview">GridView</param>
        /// <param name="fieldNameHandler">委托</param>
        /// <param name="dispalyTextHandler">展现文字</param>
        /// <param name="e">CustomColumnDisplayTextEventArgs</param>
        public static void CustomColDisplayText(this GridView girdview, Predicate<string> fieldNameHandler, Func<object, string> dispalyTextHandler, CustomColumnDisplayTextEventArgs e)
        {
            if (fieldNameHandler(e.Column.FieldName))
            {
                e.DisplayText = dispalyTextHandler(e.Value);
            }
        }
        /// <summary>
        /// CustomColumnDisplayText Helper
        /// </summary>
        /// <param name="girdview">GridView</param>
        /// <param name="valueHandler">委托</param>
        /// <param name="dispalyTextHandler">委托</param>
        /// <param name="e">CustomColumnDisplayTextEventArgs</param>
        public static void CustomColDisplayText(this GridView girdview, Func<object, Type, bool> valueHandler, Func<object, string> dispalyTextHandler, CustomColumnDisplayTextEventArgs e)
        {
            if (valueHandler(e.Value, e.Value.GetType()))
            {
                e.DisplayText = dispalyTextHandler(e.Value);
            }
        }
        /// <summary>
        /// 单元格值格式化
        /// 说明：
        /// 在CustomColumnDisplayText事件中使用
        /// 示例：
        ///  _view.CustomColDisplayText(CusTimeValues, value => string.Format("{0} %", value), e);
        /// </summary>
        /// <param name="girdview">GridView</param>
        /// <param name="columnNames">需要格式化列名称数组</param>
        /// <param name="dispalyTextHandler">条件委托</param>
        /// <param name="e">CustomColumnDisplayTextEventArgs</param>
        public static void CustomColDisplayText(this GridView girdview, string[] columnNames, Func<object, string> dispalyTextHandler, CustomColumnDisplayTextEventArgs e)
        {
            if (columnNames.Contains(e.Column.Name))
            {
                e.DisplayText = dispalyTextHandler(e.Value);
            }
        }
        /// <summary>
        ///CustomColumnDisplayText Helper
        /// </summary>
        /// <param name="girdview">GridView</param>
        /// <param name="valueHandler">委托</param>
        /// <param name="curdispalyText">展现文字</param>
        /// <param name="e">CustomColumnDisplayTextEventArgs</param>
        public static void CustomColDisplayText(this GridView girdview, Func<object, Type, bool> valueHandler, string curdispalyText, CustomColumnDisplayTextEventArgs e)
        {
            if (valueHandler(e.Value, e.Value.GetType()))
            {
                e.DisplayText = curdispalyText;
            }
        }
        #endregion
        #region 为列头绘制CheckBox
        /// <summary>
        /// 为列头绘制CheckBox
        /// </summary>
        /// <param name="view">GridView</param>
        /// <param name="checkItem">RepositoryItemCheckEdit</param>
        /// <param name="fieldName">需要绘制Checkbox的列名</param>
        /// <param name="e">ColumnHeaderCustomDrawEventArgs</param>
        public static void DrawHeaderCheckBox(this GridView view, RepositoryItemCheckEdit checkItem, string fieldName, ColumnHeaderCustomDrawEventArgs e)
        {
            /*说明：
             *参考：https://www.devexpress.com/Support/Center/Question/Details/Q354489
             *在CustomDrawColumnHeader中使用
             *eg：
             * private void gvCabChDetail_CustomDrawColumnHeader(object sender, DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs e)
             * {
             * GridView _view = sender as GridView;
             * _view.DrawHeaderCheckBox(CheckItem, "Check", e);
             * }
             */
            if (e.Column != null && e.Column.FieldName.Equals(fieldName))
            {
                e.Info.InnerElements.Clear();
                e.Painter.DrawObject(e.Info);
                DrawCheckBox(checkItem, e.Graphics, e.Bounds, getCheckedCount(view, fieldName) == view.DataRowCount);
                e.Handled = true;
            }
        }
        private static void DrawCheckBox(RepositoryItemCheckEdit checkItem, Graphics g, Rectangle r, bool Checked)
        {
            CheckEditViewInfo _info;
            CheckEditPainter _painter;
            ControlGraphicsInfoArgs _args;
            _info = checkItem.CreateViewInfo() as CheckEditViewInfo;
            _painter = checkItem.CreatePainter() as CheckEditPainter;
            _info.EditValue = Checked;

            _info.Bounds = r;
            _info.PaintAppearance.ForeColor = Color.Black;
            _info.CalcViewInfo(g);
            _args = new ControlGraphicsInfoArgs(_info, new DevExpress.Utils.Drawing.GraphicsCache(g), r);
            _painter.Draw(_args);
            _args.Cache.Dispose();
        }
        #endregion
        #region 同步列头checkbox与列中checkbox状态
        /// <summary>
        /// 同步列头checkbox与列中checkbox状态
        /// </summary>
        /// <param name="view">GridView</param>
        /// <param name="fieldeName">需要绘制Checkbox的列名</param>
        /// <param name="e">MouseEventArgs</param>
        public static void SyncCheckStatus(this GridView view, string fieldeName, MouseEventArgs e)
        {
            /*说明：
             *在MouseDown事件中使用
             *参考：https://www.devexpress.com/Support/Center/Question/Details/Q354489
             *eg:
             *private void gvLampConfig_MouseDown(object sender, MouseEventArgs e)
             *{
             *GridView _view = sender as GridView;
             *_view.SyncCheckStatus(gcCheckFieldName, e);
             *}
             */
            if (e.Clicks == 1 && e.Button == MouseButtons.Left)
            {
                view.ClearSorting();
                view.PostEditor();
                GridHitInfo _info;
                Point _pt = view.GridControl.PointToClient(Control.MousePosition);
                _info = view.CalcHitInfo(_pt);
                if (_info.InColumn && _info.Column.FieldName.Equals(fieldeName))
                {
                    if (getCheckedCount(view, fieldeName) == view.DataRowCount)
                        UnChekAll(view, fieldeName);
                    else
                        CheckAll(view, fieldeName);
                }
            }
        }
        private static int getCheckedCount(GridView view, string filedName)
        {
            int count = 0;
            for (int i = 0; i < view.DataRowCount; i++)
            {
                object _cellValue = view.GetRowCellValue(i, view.Columns[filedName]);
                //if (_cellValue != null && !(_cellValue is DBNull))
                if (_cellValue == null) continue;
                if (string.IsNullOrEmpty(_cellValue.ToString().Trim())) continue;
                bool _checkStatus = false;
                if (bool.TryParse(_cellValue.ToString(), out _checkStatus))
                {
                    //if ((bool)_cellValue)
                    if (_checkStatus)
                        count++;
                }
            }
            return count;
        }
        private static void CheckAll(GridView view, string fieldName)
        {
            for (int i = 0; i < view.DataRowCount; i++)
            {
                view.SetRowCellValue(i, view.Columns[fieldName], true);
            }
        }
        private static void UnChekAll(GridView view, string fieldName)
        {
            for (int i = 0; i < view.DataRowCount; i++)
            {
                view.SetRowCellValue(i, view.Columns[fieldName], false);
            }
        }
        #endregion
        #region 单元格验证
        /// <summary>
        /// 单元格验证
        /// </summary>
        /// <param name="view">GridView</param>
        /// <param name="name">需要验证的字段名称</param>
        /// <param name="errorHanlder">委托</param>
        /// <param name="errorText">当验证不通过对时候，错误提示信息文字</param>
        /// <param name="e">BaseContainerValidateEditorEventArgs</param>

        public static void CustomValidatingEditor(this GridView view, string name, Predicate<object> errorHanlder, string errorText, BaseContainerValidateEditorEventArgs e)
        {
            /*说明
             *在ValidatingEditor事件使用
             *eg:
             *string[] workType = new string[4] { "-1", "关闭但不删除", "启用", "删除" };
             *void gvLampConfig_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
             *{
             * GridView _view = sender as GridView;
             * _view.CustomValidatingEditor("TLTUNo", value => !string.IsNullOrEmpty(value.ToString()) && !value.ToString().IsBetween(0, 101), "请输入1~100的LTU号码，若想不修改清空单元格即可!", e);
             * }
             */
            if (view.FocusedColumn.Name.Equals(name))
            {
                if (errorHanlder(e.Value))
                {
                    e.Valid = false;
                    e.ErrorText = errorText;
                }
            }
        }
        /// <summary>
        /// 单元格验证
        /// </summary>
        /// <param name="view">GridView</param>
        /// <param name="errorHanlder">条件委托</param>
        /// <param name="errorText">当验证不通过对时候，错误提示信息文字</param>
        /// <param name="e">BaseContainerValidateEditorEventArgs</param>
        public static void CustomValidatingEditor(this GridView view, Predicate<object> errorHanlder, string errorText, BaseContainerValidateEditorEventArgs e)
        {
            if (errorHanlder(e.Value))
            {
                e.Valid = false;
                e.ErrorText = errorText;
            }
        }
        /// <summary>
        /// 单元格验证
        /// </summary>
        /// <param name="view">GridView</param>
        /// <param name="names">需要验证的字段名称数组</param>
        /// <param name="errorHanlder">委托</param>
        /// <param name="errorText">当验证不通过对时候，错误提示信息文字</param>
        /// <param name="e">BaseContainerValidateEditorEventArgs</param>

        public static void CustomValidatingEditor(this GridView view, string[] names, Predicate<object> errorHanlder, string errorText, BaseContainerValidateEditorEventArgs e)
        {
            /*说明
             *在ValidatingEditor事件使用
             *eg:
             *string[] workType = new string[4] { "-1", "关闭但不删除", "启用", "删除" };
             *void gvLampConfig_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
             *{
             * GridView _view = sender as GridView;
             * _view.CustomValidatingEditor("TLTUNo", value => !string.IsNullOrEmpty(value.ToString()) && !value.ToString().IsBetween(0, 101), "请输入1~100的LTU号码，若想不修改清空单元格即可!", e);
             * }
             */
            if (names.Contains(view.FocusedColumn.Name))
            {
                if (errorHanlder(e.Value))
                {
                    e.Valid = false;
                    e.ErrorText = errorText;
                }
            }
        }
        #endregion
        #region 根据列来选中一行
        /// <summary>
        /// 根据列来选中一行
        /// </summary>
        /// <param name="gridView">GridView</param>
        /// <param name="colName">列名称</param>
        /// <param name="colValue">列值</param>
        public static void SelectRow(this GridView gridView, string colName, object colValue)
        {
            gridView.ClearSelection();
            for (int rowHandle = 0; rowHandle < gridView.RowCount; rowHandle++)
            {
                object _cellValue = gridView.GetRowCellValue(rowHandle, colName);
                if (_cellValue != null)
                {
                    if (_cellValue == colValue)
                    {
                        gridView.SelectRow(rowHandle);
                        gridView.FocusedRowHandle = rowHandle;
                        break;
                    }
                }
            }
        }
        #endregion
        #region 删除全部行
        /// <summary>
        /// 删除全部行
        /// </summary>
        /// <param name="gridView">GridView</param>
        public static void ClearRows(this GridView gridView)
        {
            bool _mutilSelected = gridView.OptionsSelection.MultiSelect;//获取当前是否可以多选
            if (!_mutilSelected)
                gridView.OptionsSelection.MultiSelect = true;
            gridView.SelectAll();
            gridView.DeleteSelectedRows();
            gridView.OptionsSelection.MultiSelect = _mutilSelected;//还原之前是否可以多选状态
        }
        #endregion
        #region 设置RepositoryItem是否可编辑
        /// <summary>
        /// 设置RepositoryItem是否可编辑
        /// 说明：
        /// 在ShowingEditor事件中使用
        /// </summary>
        /// <param name="view">GridView</param>
        /// <param name="focusedColumnName">需要设置的列名称</param>
        /// <param name="conditonHanlder">判断委托</param>
        /// <param name="toolTip">ToolTipController</param>
        /// <param name="title">当条件委托成立的时候提示标题</param>
        /// <param name="content">当条件委托成立的时候提示内容</param>
        /// <param name="e">CancelEventArgs</param>
        public static void CustomShowingEditorWithToolTip(this GridView view, string focusedColumnName, Func<object, bool> conditonHanlder, ToolTipController toolTip, string title, string content, CancelEventArgs e)
        {
            if (view.FocusedColumn.Name.Equals(focusedColumnName))
            {
                if (conditonHanlder(view.GetFocusedRow()))
                {
                    e.Cancel = true;
                    Point _mousePoint = Control.MousePosition;
                    toolTip.ShowHint(content, title, _mousePoint);
                }
            }
        }
        /// <summary>
        /// 设置RepositoryItem是否可编辑
        /// 说明：
        /// 在ShowingEditor事件中使用
        /// </summary>
        /// <param name="view">GridView</param>
        /// <param name="focusedColumnNames">需要设置的列名称数组</param>
        /// <param name="conditonHanlder">判断委托</param>
        /// <param name="toolTip">ToolTipController</param>
        /// <param name="title">当条件委托成立的时候提示标题</param>
        /// <param name="content">当条件委托成立的时候提示内容</param>
        /// <param name="e">CancelEventArgs</param>
        public static void CustomShowingEditorWithToolTip(this GridView view, string[] focusedColumnNames, Func<object, bool> conditonHanlder, ToolTipController toolTip, string title, string content, CancelEventArgs e)
        {
            if (focusedColumnNames.Contains(view.FocusedColumn.Name))
            {
                if (conditonHanlder(view.GetFocusedRow()))
                {
                    e.Cancel = true;
                    Point _mousePoint = Control.MousePosition;
                    toolTip.ShowHint(content, title, _mousePoint);
                }
            }
        }
        #endregion
        #region 根据rowIndex和visibleColumnsIndex来获取单元格可见值
        /// <summary>
        /// 根据rowIndex和visibleColumnsIndex来获取单元格可见值
        /// </summary>
        /// <param name="view">GridView</param>
        /// <param name="rowIndex">rowIndex</param>
        /// <param name="visibleColumnsIndex">visibleColumnsIndex</param>
        /// <returns>单元格可见值</returns>
        public static string GetRowCellDisplayText(this GridView view, int rowIndex, int visibleColumnsIndex)
        {
            return view.GetRowCellDisplayText(rowIndex, view.VisibleColumns[visibleColumnsIndex]);
        }
        /// <summary>
        /// 根据rowIndex和visibleColumnsIndex来获取单元格值
        /// </summary>
        /// <param name="view">GridView</param>
        /// <param name="rowIndex">rowIndex</param>
        /// <param name="visibleColumnsIndex">visibleColumnsIndex</param>
        /// <returns>单元格值</returns>
        public static object GetRowCellValue(this GridView view, int rowIndex, int visibleColumnsIndex)
        {
            return view.GetRowCellValue(rowIndex, view.VisibleColumns[visibleColumnsIndex]);
        }
        #endregion
        #region 根据行，列索引来获取RepositoryItem
        /// <summary>
        /// 根据行，列索引来获取RepositoryItem
        /// </summary>
        /// <param name="view">GridView</param>
        /// <param name="rowIndex">行索引</param>
        /// <param name="columnIndex">列索引</param>
        /// <returns>RepositoryItem</returns>
        public static RepositoryItem GetRepositoryItem(this GridView view, int rowIndex, int columnIndex)
        {
            GridViewInfo _viewInfo = view.GetViewInfo() as GridViewInfo;
            GridDataRowInfo _viewRowInfo = _viewInfo.RowsInfo.FindRow(rowIndex) as GridDataRowInfo;
            return _viewRowInfo.Cells[columnIndex].Editor;
        }
        #endregion
        #region 设置GridView列的可见性【线程安全】
        /// <summary>
        /// 设置GridView列的可见性【线程安全】
        /// </summary>
        /// <param name="gridView">GridView</param>
        /// <param name="columnName">列名称</param>
        /// <param name="visible">是否可见</param>
        public static void SetColumnVisibleTF(this GridView gridView, string columnName, bool visible)
        {
            if (!string.IsNullOrEmpty(columnName))
            {
                gridView.GridControl.UIThread<GridControl>(gc =>
                {
                    gridView.Columns[columnName].Visible = visible;
                });
            }
        }
        #endregion
        #region 设置GridView的可编辑性【线程安全】
        /// <summary>
        /// 设置GridView的可编辑性【线程安全】
        /// </summary>
        /// <param name="view">GridView</param>
        /// <param name="edit">是否可编辑</param>
        public static void SetEditableTF(this GridView view, bool edit)
        {
            GridControl _gridControl = view.GridControl;
            _gridControl.UIThread<GridControl>(gc =>
            {
                view.OptionsBehavior.Editable = edit;
            });
        }
        #endregion
        #region 导出到Excel
        /// <summary>
        /// 导出到Excel
        /// <para>eg:GridHelper.ToXls(gcLamp,string.Format("{0}_单灯电参数数据.xls", DateTime.Now.ToString("yyyyMMdd")));</para>
        /// </summary>
        /// <param name="grid">GridControl</param>
        /// <param name="fileName">导出到Excel文件名称</param>
        public static void ToXls(this GridControl grid, string fileName)
        {
            SaveFileDialog _saveFileDialog = new SaveFileDialog();
            _saveFileDialog.Title = "导出Excel";
            _saveFileDialog.Filter = "Excel文件(*.xls)|*.xls";
            _saveFileDialog.FileName = fileName;
            DialogResult _dialogResult = _saveFileDialog.ShowDialog();
            if (_dialogResult == DialogResult.OK)
            {
                XlsExportOptions _options = new XlsExportOptions();
                _options.Suppress256ColumnsWarning = true;
                _options.Suppress65536RowsWarning = true;
                _options.TextExportMode = TextExportMode.Text;
                grid.ExportToXls(_saveFileDialog.FileName);
                DevMessageBoxHelper.ShowInfo("导出到Excel成功！");
            }
        }
        #endregion
    }
}
